package com.ft.oa.web.project;

import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.domain.dto.project.ExecProjectDto;
import com.ft.oa.domain.dto.project.ExecProjectPage;
import com.ft.oa.domain.project.BidProjectPage;
import com.ft.oa.domain.project.ExecProject;
import com.ft.oa.domain.project.ExecProjectContract;
import com.ft.oa.service.customer.CustomerSupplierService;
import com.ft.oa.service.project.BidProjectService;
import com.ft.oa.service.project.ExecProjectService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 项目立项
 * @author hefeng
 * @ClassName ExecProjectController
 * @date 2021/12/30 10:47
 */
@RestController
@RequestMapping("/execProject")
public class ExecProjectController {

    @Resource
    private ExecProjectService execProjectService;

    @Resource
    private BidProjectService bidProjectService;

    @Resource
    private CustomerSupplierService customerSupplierService;
    /**
     * 查询可用的项目 根据创建人
     */
    @PostMapping("/allExecproject")
    public ApiResult allExecproject() {
        return execProjectService.allExecproject();
    }
    /**
     * 查询当前登录人的项目周报
     */
    @PostMapping("/allweeklyreport")
    public ApiResult allweeklyreport(@RequestBody ExecProjectPage execProjectPage) {
        return execProjectService.allweeklyreport(execProjectPage.getList());
    }

    /**
     * 新增立项
     * @param execProjectDto
     * @return
     */
    @PostMapping("/add")
    public ApiResult saveOrUpdateExecProject(@RequestBody ExecProjectDto execProjectDto){
        return execProjectService.add(execProjectDto);
    }
    /**
     * 新增成本计划和采购
     */
    @PostMapping("/addplan")
    public ApiResult addplan(@RequestBody ExecProjectDto execProjectDto){
        return execProjectService.addplan(execProjectDto);
    }

    /**
     * 新增子项目
     * @Author liyansheng
     * @param execProject
     * 2022-1-11 17:07:45
     * @return
     */
    @PostMapping("/addSub")
    public ApiResult addSub(@RequestBody ExecProject execProject){
        return execProjectService.addSub(execProject);
    }

    /**
     * 编辑立项
     * @param execProjectDto
     * @return
     */
//    @PostMapping("/update")
//    public ApiResult update(@RequestBody ExecProjectDto execProjectDto){
//        return execProjectService.update(execProjectDto);
//    }

    /**
     * 编辑子项目
     * @param execProject
     * @return
     */
    @PostMapping("/updateSub")
    public ApiResult updateSub(@RequestBody ExecProject execProject){
        return execProjectService.updateSub(execProject);
    }

    /**
     * param name项目名称
     * describe 项目立项管理列表
     * @author 禾丰
     * @date 2022/1/4
     */
    @PostMapping("/page")
    public ApiResult list(@RequestBody ExecProjectPage execProjectPage){
        return execProjectService.list(execProjectPage);
    }

    /**
     * param id 项目立项id
     * return  ExecProjectDetailVo项目立项详情
     * describe 项目立项详情
     * @author 禾丰
     * @date 2022/1/4
     */
    @PostMapping("/detail/{id}")
    public ApiResult detail(@PathVariable Long id){
        return execProjectService.detail(id);
    }


    /**
     * 根据id删除立项数据（项目删除的同时删除子项目）
     * @param id
     * @author liyansheng
     * @return
     */
    @PostMapping("/del/{id}")
    public ApiResult del(@PathVariable Long id){
        return ApiResult.successWithData(execProjectService.del(id));
    }

    /**
     * 根据id删除子项目
     * @param projectNumber
     * @author liyansheng
     * @return
     */
    @PostMapping("/delSub/{projectNumber}")
    public ApiResult delSub(@PathVariable String projectNumber){
        return ApiResult.successWithData(execProjectService.delSub(projectNumber));
    }


    /**
     * 统计编码是否存在，不存在返回0，存在返回1
     * param projectNumber
     * return int
     * @author liyansheng
     * @date 2022-1-10 16:43:50
     */
    @PostMapping("/select/{projectNumber}")
    public ApiResult select(@PathVariable String projectNumber){
        return ApiResult.successWithData(execProjectService.select(projectNumber));
    }

    /**
     * 目前废弃了
     * param id 项目立项id
     * return  ExecProject
     * describe 子项目详情
     * @author 禾丰
     * @date 2022/1/4
     */
    @PostMapping("/subDetail/{id}")
    public ApiResult subDetail(@PathVariable Long id){
        return ApiResult.successWithData(execProjectService.subDetail(id));
    }


    /**
     * 子项目参与阶段
     * @param projectNumber
     * @Author liyansheng
     * @return
     */
    @PostMapping("/selectStage/{projectNumber}")
    public ApiResult selectStage(@PathVariable String projectNumber){
        return ApiResult.successWithData(execProjectService.selectStage(projectNumber));
    }

    /**
     * 更新阶段状态为已验收  （该接口再验收的时候调用）
     * @param id
     * @return
     */
    @PostMapping("/changeStage/{id}")
    public ApiResult changeStage(@PathVariable("id") Long id){
        ApiResult result = execProjectService.changeStage(id);
        return result;
    }

    /**
     * 子项目参与合同
     * @param projectNumber
     * @Author liyansheng
     * @return
     */
    @PostMapping("/selectContract/{projectNumber}")
    public ApiResult selectContract(@PathVariable String projectNumber){
        List<ExecProjectContract> execProjectContracts = execProjectService.selectContract(projectNumber);
        return ApiResult.successWithData(execProjectContracts);
    }

    /**
     * 修改合同数据、同时修改合同状态为已验收
     * @param execProjectContracts
     * @Author liyansheng
     * @return
     */
    @PostMapping("/updateContract")
    public ApiResult updateContract(@RequestBody List<ExecProjectContract> execProjectContracts){
        return ApiResult.successWithData(execProjectService.updateContract(execProjectContracts));
    }

    /**
     * 父项目下拉接口（审批通过的）
     * @param
     * @Author liyansheng
     * @Time 2022-1-12 11:14:11
     * @return
     */
    @PostMapping("/selectProjects")
    public ApiResult selectProjects(){
        return ApiResult.successWithData(execProjectService.selectProjects());
    }

    /**
     * 项目经理、子项目负责人接口（后去确定权限后再进行分离）
     * @param
     * @Author liyansheng
     * @return
     */
    @PostMapping("/manager")
    public ApiResult manager(){
        return ApiResult.successWithData(execProjectService.manager());
    }

    /**
     * 项目经理、子项目负责人接口（后去确定权限后再进行分离）
     * @param
     * @Author liyansheng
     * @return
     */
    @PostMapping("/users")
    public ApiResult users(){
        return ApiResult.successWithData(execProjectService.users());
    }

    /**
     * 部门（后去确定权限后再进行分离）
     * @param
     * @Author liyansheng
     * @return
     */
    @PostMapping("/dept")
    public ApiResult dept(){
        return ApiResult.successWithData(execProjectService.dept());
    }

    /**
     * 合同附件上传
     * @param files
     *
     * @return
     */
    @GetMapping("/uploadContract")
    public ApiResult uploadContract(@RequestParam("files") MultipartFile files[]) {
        ApiResult result = bidProjectService.upload(files,"项目立项-合同附件");
        return result;
    }

    /**
     * 子项目合同附件上传
     * @param files
     *
     * @return
     */
    @GetMapping("/uploadSub")
    public ApiResult uploadSub(@RequestParam("files") MultipartFile files[]) {
        ApiResult result = bidProjectService.upload(files,"项目执行管理-子项目合同附件");
        return result;
    }

    /**
     * 分页查询待立项招投标项目（中标状态、未立项）
     * @return
     */
    @PostMapping("/toProjectPage")
    public ApiResult winPage(@RequestBody BidProjectPage bidpage){
        //查询所有中标的项目
        bidpage.setBidResult(3);
        //查询未立项项目
        bidpage.setToProject(0);
        ApiResult result = bidProjectService.page(bidpage);
        return result;
    }

    /**
     * 首签项目接口  查询所有售前项目
     * @param
     * @Author liyansheng
     * @return
     */
    @PostMapping("/clueProject")
    public ApiResult clueProject(){
        return ApiResult.successWithData(execProjectService.clueProject());
    }

    ///以下新增编辑页面删除操作  包含删除阶段、合同、预算、参与人员、审批人、抄送人


    /**
     * 根据id删除立项数据（项目删除的同时删除子项目）
     * type: stage-阶段 contract-合同 cost-预算 contributor-参与人员 check-审批人 notice-抄送人
     * @param type,id
     * @author liyansheng
     * @return
     */
    @PostMapping("/del/{type}/{id}")
    public ApiResult del(@PathVariable("type") String type,@PathVariable("id") Long id){
        return ApiResult.successWithData(execProjectService.delUpdate(type,id));
    }

    /**
     * 供应商下拉接口
     * @param
     * @Author liyansheng
     * @return
     */
    @PostMapping("/supplier")
    public ApiResult supplier(){
        return ApiResult.successWithData(customerSupplierService.select());
    }

    /**
     * 根据公司编码查询审批通过的父项目
     * @param id
     * @return
     */
    @PostMapping("/getListBySql/{id}")
    public int getListBySql(@PathVariable("id") Long id){
        return execProjectService.getListBySql(id);
    }

    /**
     * 生成子项目编号
     * @return
     */
    @PostMapping("/sub")
    public ApiResult SubSerial(@RequestBody ExecProject execProject){
        String s = execProjectService.SubSerial(execProject);
        return ApiResult.successWithData(s);
    }

    /**
     * 查询所有所有审批通过的父项目
     * @return
     */
    @PostMapping("/getPars")
    public ApiResult getPars(){
        List<ExecProject> pars = execProjectService.getPars();
        return ApiResult.successWithData(pars);
    }
}
